﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Client;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.Clientss
{
    public class ClientManagementAddHandler : IRequestHandler<ClientManagementAddCommand, ResultsDTO>
    {
        private readonly IBateRepository<ClientManagement> Clientes;
        public ClientManagementAddHandler(IBateRepository<ClientManagement> Clientes)
        {
           this. Clientes = Clientes;
        }
        public async Task<ResultsDTO> Handle(ClientManagementAddCommand request, CancellationToken cancellationToken)
        {
            DapperHelper helper = new DapperHelper();
            ResultsDTO res = new ResultsDTO { Code = 0 };
            ClientManagement  clientess=new ClientManagement();
            clientess.ClientId = request.ClientId;
            clientess.ClientNo = request.ClientNo;
            clientess.ClientName = request.ClientName;
            clientess.ClientAName = request.ClientAName;
            clientess.ClientEname = request.ClientEname;
            clientess.ClientTypeId = request.ClientTypeId;
            clientess.ClientSynopsis = request.ClientSynopsis;
            clientess.ClientSite = request.ClientSite;
            clientess.ClientWebsite = request.ClientWebsite;
            clientess.ClientEmail = request.ClientEmail;
            clientess.ClientPhone = request.ClientPhone;
            clientess.ClientLogo = request.ClientLogo;
            clientess.ClientContact1 = request.ClientContact1;
            clientess.ClientPhone1 = request.ClientPhone1;
            clientess.ClientEmail1 = request.ClientEmail1;
            clientess.ClientContact2 = request.ClientContact2;
            clientess.ClientPhone2 = request.ClientPhone2;
            clientess.ClientEmail2 = request.ClientEmail2;
            clientess.SocialCreditCode = request.SocialCreditCode;
            clientess.IsVaild = request.IsVaild; 
            clientess.Remark = request.Remark;
            clientess.IsNo = 0;
            string conn = helper.MangoMesWrite;
            string str = "insert into clientmanagement values(@ClientId,@ClientNo,@ClientName,@ClientAName,@ClientEname,@ClientTypeId,@ClientSynopsis,@ClientSite,@ClientWebsite,@ClientEmail,@ClientPhone,@ClientLogo,@ClientContact1,@ClientPhone1,@ClientEmail1,@ClientContact2,@ClientPhone2,@ClientEmail2,@SocialCreditCode,@IsVaild,@Remark,@IsNo)";
            res.Code = await Clientes.Add(str, clientess, conn);
            return res;
        }
    }
}
